%% This is file ntuthesis.cls
%  @author oldoldstone,2017/03/10
%  @modified date 2021/03/16
%
%  Copyright 2017- oldoldstone <oldoldstone@gmail.com>
%
%  This program is free software; you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published by
%  the Free Software Foundation; either version 2 of the License, or
%  (at your option) any later version.
%
%  This program is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.
%
%  You should have received a copy of the GNU General Public License
%  along with this program; if not, write to the Free Software
%  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
%  MA 02110-1301, USA.
%

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{ntuthesis}
\typeout{Document Class `ntuthesis' v1.0.1 Wang Meng,  (2021/03/16)}
\newif\ifbachelordegree\bachelordegreetrue %缺省本科论文
\newif\ifproject\projectfalse %毕业设计
\newif\ifmasterdegree\masterdegreefalse %硕士论文
\newif\iffulltime\fulltimetrue  %全日制
\newif\ifequivalent\equivalentfalse %同等学力
\newif\ifacdemic\acdemictrue %学术型
\newif\ifprofessional\professionalfalse %专业型
\newif\ifcoadvisor\coadvisorfalse
\DeclareOption{bachelor}{\bachelordegreetrue\projectfalse}
\DeclareOption{project}{\bachelordegreetrue\projecttrue}
\DeclareOption{master}{\masterdegreetrue\bachelordegreefalse}
\DeclareOption{fulltime}{\fulltimetrue\equivalentfalse}
\DeclareOption{equivalent}{\bachelordegreefalse\masterdegreetrue\equivalenttrue\fulltimefalse}
\DeclareOption{acdemic}{\acdemictrue\professionalfalse}
\DeclareOption{professional}{\professionaltrue\acdemicfalse}
\ProcessOptions
%添加文档属性
\newcommand{\@authoreng}{} %作者英文名
\renewcommand{\author}[2]{
  \renewcommand{\@authoreng}{#1}
  \def\@author{#2}
}
\newcommand{\@titleeng}{}
\renewcommand{\title}[2]{
  \renewcommand{\@titleeng}{#1}
  \def\@title{#2}
}
\newcommand{\@advisorname}{}
\newcommand{\@advisortitle}{}
\newcommand{\@advisornameeng}{}
\newcommand{\@advisortitleeng}{}
\newcommand{\advisor}[4]{
  \renewcommand{\@advisortitle}{#1}
  \renewcommand{\@advisornameeng}{#2}
  \renewcommand{\@advisortitleeng}{#3}
  \renewcommand{\@advisorname}{#4}
}
\newcommand{\@coadvisorname}{}
\newcommand{\@coadvisortitle}{}
\newcommand{\@coadvisornameeng}{}
\newcommand{\@coadvisortitleeng}{}
\newcommand{\coadvisor}[4]{
 \coadvisortrue
 \renewcommand{\@coadvisortitle}{#1}
 \renewcommand{\@coadvisornameeng}{#2}
 \renewcommand{\@coadvisortitleeng}{#3}
 \renewcommand{\@coadvisorname}{#4}
}
\newcommand{\@subjectname}{}
\newcommand{\@major}{}
\newcommand{\@researchfield}{}
\newcommand{\research}[3]{
  \renewcommand{\@subjectname}{#1}
  \renewcommand{\@major}{#2}
  \renewcommand{\@researchfield}{#3}
}
\newcommand{\@school}{}
\newcommand{\school}[1]{\renewcommand{\@school}{#1}}
\newcommand{\@finishdate}{}
\newcommand{\finishdate}[1]{\renewcommand{\@finishdate}{#1}}
\newcommand{\@studentid}{}
\newcommand{\studentid}[1]{\renewcommand{\@studentid}{#1}}
\newcommand{\@categorynumber}{}
\newcommand{\categorynumber}[1]{\renewcommand{\@categorynumber}{#1}}
\newcommand{\@univnumber}{}
\newcommand{\univnumber}[1]{\renewcommand{\@univnumber}{#1}}
\newcommand{\@subjectnumder}{}
\newcommand{\subjectnumder}[1]{\renewcommand{\@subjectnumder}{#1}}
\newcommand{\@foundation}{}
\newcommand{\foundation}[1]{\renewcommand{\@foundation}{#1}}
\newcommand{\@aplydegree}{}
\newcommand{\aplydegree}[1]{\renewcommand{\@aplydegree}{#1}}

\newcommand{\Hsquare}{%
  \text{\fboxsep=-.2pt\fbox{\rule{0pt}{1ex}\rule{1ex}{0pt}}}%
}
%%% 宏包设置
\LoadClass[12pt,a4paper,oneside]{book}
\RequirePackage[zihao=-4,UTF8,fntef]{ctex}%支持中文
\RequirePackage{setspace}
\RequirePackage{geometry} %[showframe]
\RequirePackage{fancyhdr}
\RequirePackage{float}
\RequirePackage{graphicx}
\RequirePackage{amsmath} %使用ams的数学库
\RequirePackage{amssymb}
\usepackage{unicode-math} %自定义公式字体，否则某些特殊字符无法显示
\RequirePackage{titletoc}
\RequirePackage{zhnumber}
\RequirePackage{ulem}%下划线跨行
\usepackage{CJKulem}%中文下划线跨行
\RequirePackage{stringstrings}%字符串处理
\RequirePackage{tikz}%绘制图形
\RequirePackage{dashrule}
\usetikzlibrary{decorations.markings}

% 绘制研究生授权页粗的点划线
\newcommand{\dhorline}[3][0]{
    \tikz[baseline]{\path[decoration={markings,
      mark=between positions 0 and 1 step 2*#3
      with {\node[fill, circle, minimum width=#3, inner sep=0pt, anchor=south west] {};}},postaction={decorate}]  (0,#1) -- ++(#2,0);}}
\renewcommand{\thefootnote}{\textcircled{\arabic{footnote}}}

%%% chapter的hack，否则每章第一页没有页眉
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\patchcmd*{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

%%% 设置中文字体
\setmainfont{Times New Roman}%英文缺省字体
\setmonofont{Courier New}
\setsansfont{Arial}
\setCJKfamilyfont{kai}[AutoFakeBold]{楷体}
\newcommand*{\kai}{\CJKfamily{kai}}
\setCJKfamilyfont{song}[AutoFakeBold]{SimSun}
\newcommand*{\song}{\CJKfamily{song}}
\setCJKfamilyfont{fsong}[AutoFakeBold]{仿宋}
\newcommand*{\fsong}{\CJKfamily{fsong}}
\setCJKfamilyfont{heiti}[AutoFakeBold]{SimHei}
\renewcommand*{\heiti}{\CJKfamily{heiti}}
%字号与pt值的转换
\newcommand{\chuhao}{\fontsize{42pt}{\baselineskip}\selectfont}
\newcommand{\xiaochu}{\fontsize{36pt}{\baselineskip}\selectfont}
\newcommand{\sanshi}{\fontsize{30pt}{\baselineskip}\selectfont}
\newcommand{\yihao}{\fontsize{28pt}{\baselineskip}\selectfont}
\newcommand{\xiaoyi}{\fontsize{24pt}{\baselineskip}\selectfont}
\newcommand{\erhao}{\fontsize{22pt}{\baselineskip}\selectfont}
\newcommand{\xiaoer}{\fontsize{18pt}{\baselineskip}\selectfont}
\newcommand{\sanhao}{\fontsize{16pt}{\baselineskip}\selectfont}
\newcommand{\xiaosan}{\fontsize{15pt}{\baselineskip}\selectfont}
\newcommand{\sihao}{\fontsize{13.75pt}{\baselineskip}\selectfont}
\newcommand{\xiaosi}{\fontsize{12pt}{\baselineskip}\selectfont}
\newcommand{\wuhao}{\fontsize{10.5pt}{\baselineskip}\selectfont}
\newcommand{\xiaowu}{\fontsize{9pt}{\baselineskip}\selectfont}

%改变中文字符间距
\newcommand\Zhspace[2]{
\let\oldCJKglue\CJKglue
\renewcommand{\CJKglue}{\hskip #1 plus 0.08\baselineskip}
{#2}%
\let\CJKglue\oldCJKglue
}
%\xeCJKEditPunctStyle{quanjiao}{optimize-kerning=true} %中文标点优化，好像没啥用

%%% 无编号章，但加入目录，如致谢，参考文献
\newcommand\sectionstar[1]{%
  \section*{#1}%
  \addcontentsline{toc}{section}{#1}}
\newcommand\chapterstar[1]{%
  \chapter*{#1}%
  \addcontentsline{toc}{chapter}{#1}}

%页面设置
%\geometry{left=3.2cm,right=3.2cm,top=3.8cm,tmargin=3.5cm,bottom=3.8cm,bmargin=4cm}
%\setlength{\headsep}{0.2cm}
%\setlength{\footskip}{1cm}
\ifbachelordegree
  \geometry{left=3cm,right=1.5cm,top=2.5cm,bottom=2cm,} %本科页面
\else
  \geometry{left=3.2cm,right=3.2cm,top=3cm,bottom=3cm} %研究生论文页面
  \setlength{\headsep}{1cm}
  \setlength{\footskip}{0.8cm}
  %\geometry{left=3.2cm,right=3.2cm,top=3.8cm,tmargin=3.5cm,bottom=3.8cm,bmargin=4cm}
  %\setlength{\headsep}{0.2cm}
  %\setlength{\footskip}{1cm}
\fi

% 使用fancyhdr库定义页眉页脚
\fancypagestyle{graduatestyle}{%硕士页眉页脚
  \fancyhf{} %清空原有样式
  \fancyhead[L]{\wuhao\lan@university\lan@master\lan@degree\lan@paper}
  \fancyfoot[C]{\xiaowu\thepage}
}
\fancypagestyle{bachelorstyle}{%本科页眉页脚
  \fancyhf{} %清空原有样式
  \fancyhead[L]{
    \xiaowu\lan@university\lan@graduation\ifproject\lan@project\else\lan@paper\fi
  }
  \fancyfoot[C]{\xiaowu\thepage}
}
\ifbachelordegree
  \pagestyle{bachelorstyle}
\else
  \pagestyle{graduatestyle}
\fi

%%定义本科论文外封面
\newcommand\titlebachelor{
  \newgeometry{left=3.18cm,right=3.18cm,top=2.54cm,bottom=2.54cm} %封面页边距对称
  \begin{center}{%
    \vspace*{60pt}
    \includegraphics[width=12cm]{img/ntdx}\\
    \includegraphics[width=3.8cm]{img/logo}\\
    \vspace*{10pt}
    \ifproject
      {\chuhao\heiti\bfseries\Zhspace{5pt}{\lan@bachelor\lan@graduation\lan@project}}\\
    \else
      {\chuhao\heiti\bfseries\Zhspace{5pt}{\lan@bachelor\lan@graduation\lan@paper}}\\
    \fi
    \vspace*{15pt}
    \begin{tabular}{|c|c|}
      \hline
      \begin{minipage}[t][60pt][c]{7mm}%
      \vspace{4mm}
      \begin{center}
      \begin{spacing}{1.8}{\xiaoer\bfseries\lan@title}\end{spacing}
      \end{center}
      \end{minipage} & \multicolumn{1}{c|}{%
      \begin{minipage}[t][60pt][c]{95mm}%
      \vspace{4mm}
      \begin{center}
      \begin{spacing}{1.8}{\xiaoer\bfseries\@title}\end{spacing}
      \end{center}
      \end{minipage}}\tabularnewline
      \hline
    \end{tabular}\\
    \vspace*{98pt}
    \begin{tabular}{cc}
      \begin{minipage}[t][30pt]{28mm}{\xiaoer\heiti\bfseries\lan@author\lan@colon}\end{minipage}&
      \hspace{-10pt}\underline{\makebox[60mm]{\xiaoer\@author}}\tabularnewline
      \begin{minipage}[t][30pt]{28mm}{\xiaoer\heiti\bfseries\lan@major\lan@colon}\end{minipage}&
      \hspace{-10pt}\underline{\makebox[60mm]{\xiaoer\@major}}\tabularnewline
      \begin{minipage}[t][30pt]{28mm}{\xiaoer\heiti\bfseries\lan@supervisor\lan@colon}\end{minipage}&
      \hspace{-10pt}\underline{\makebox[60mm]{\xiaoer\@advisorname}}\tabularnewline
      \begin{minipage}[t][30pt]{28mm}{\xiaoer\heiti\bfseries\lan@finishdate\lan@colon}\end{minipage}&
      \hspace{-10pt}\underline{\makebox[60mm]{\xiaoer\@finishdate}}\tabularnewline
    \end{tabular}
  }
  \end{center}
  \clearpage
}

%本科论文声明与授权书页
\newcommand{\statementbachelor}{
  \thispagestyle{empty}
  \newgeometry{left=3.18cm,right=3.18cm,top=2.54cm,bottom=2.54cm} %封面页边距对称
  \vspace*{10mm}
  \begin{center}{\erhao\bfseries\Zhspace{14pt}{\lan@bachelorstaementname}}\end{center}
  \begin{spacing}{1.35}
    \vspace{6mm}\par\sihao\lan@bachelorstaement
    \par\vspace{15mm}
    \rightline{
      \Zhspace{12pt}{\lan@signature}\lan@colon\underline{\makebox[25mm]{}}
      \Zhspace{12pt}{\lan@date}\lan@colon\underline{\makebox[25mm]{}}
    }
    \vspace{4em}\begin{center}{\erhao\bfseries\lan@bachelorauthtitle}\end{center}
    \vspace{6mm}\par\lan@bachelorauthorization
    \par{\bfseries \hspace{5mm}\lan@privacy}
    \par\vspace{14mm} \rightline{
      \lan@student\lan@signature\lan@colon\underline{\makebox[18mm]{}}
      \lan@advisor\lan@signature\lan@colon\underline{\makebox[18mm]{}}
      \Zhspace{12pt}{\lan@date}\lan@colon\underline{\makebox[20mm]{}}
    }
  \end{spacing}
  \clearpage

  \restoregeometry
}

%本科论文内封面
\newcommand{\coverbachelor}{
  \clearpage
  \thispagestyle{empty}
  \begin{center}
  \begin{spacing}{2.5}
    \vspace*{1mm}{\erhao\Zhspace{12pt}{\lan@university}\par\xiaoyi
        \Zhspace{12pt}{\lan@graduation\ifproject\lan@project\else\lan@paper\fi}}
  \end{spacing}
  \par\vspace*{32mm}
  \begin{tabular}{cc}
  \begin{minipage}[t]{15mm}%
    {\sanhao \lan@title\lan@colon}
  \end{minipage} & %
  \begin{minipage}[t]{110mm}{
    \begin{spacing}{1.4}\centering\sanhao\uline{\hfill\@title\hfill}\end{spacing}
  }\end{minipage}\tabularnewline
  \end{tabular}
  \par\vspace*{30mm}
      \begin{tabular}{cc}
        \begin{minipage}[t][30pt]{28mm}{\xiaoer\lan@author\lan@colon}\end{minipage} &
        \underline{\makebox[60mm]{\xiaoer\@author}}\tabularnewline
        \begin{minipage}[t][30pt]{28mm}{\xiaoer\lan@supervisor\lan@colon}\end{minipage} &
        \underline{\makebox[60mm]{\xiaoer\@advisorname}}\tabularnewline
        \begin{minipage}[t][30pt]{28mm}{\xiaoer\lan@major\lan@colon}\end{minipage} &
        \underline{\makebox[60mm]{\xiaoer \@major}}\tabularnewline
      \end{tabular}
  \par\vspace*{24mm}
    {\begin{spacing}{1.5} \sanhao \@school \\ \@finishdate \end{spacing}}
  \clearpage
  \end{center}
}

%研究生论文外封面
\newcommand\titlegraduate{
\newgeometry{left=2.5cm,right=2.2cm,top=2.9cm,bottom=2.2cm} %封面页边距对称
\begin{center}{%
    \leftline{\hspace{18pt}\xiaosi\song\bfseries{\lan@classification\lan@colon}
      \hspace{2bp}\underline{\makebox[30mm]{\xiaosi\@categorynumber}}\hfill
      \xiaosi\song\bfseries{\lan@univcode\lan@colon}
      \hspace{2bp}\underline{\makebox[20mm]{\xiaosi\@univnumber}}
    }
    \vspace*{36pt}
    \includegraphics[height=2.34cm]{img/ntdx}\\
    \vspace*{12pt}
    %旧封面
    %{\yihao\song\bfseries\Zhspace{1pt}{\lan@equivalent\lan@degree\lan@paper}}\\
    %\vspace*{20pt}{\yihao\song\bfseries{（\lan@acdegree）}}\\
    {\hspace{-20pt}\iffulltime
      \sanshi\song\bfseries\Zhspace{5pt}{\lan@degree\lan@paper}\ifacdemic（\lan@acdemic）\else（\lan@professional）\fi
    \else
      \sanshi\song\bfseries{\lan@equivalentpaper}\ifacdemic（\lan@acdemic）\else（\lan@professional）\fi
    \fi
    } \\
    \vspace*{10pt}\includegraphics[height=3.78cm]{img/logo}\\
    \vspace*{36pt}
    \hspace{20pt}{\parbox[t]{12cm}{\fsong\xiaoer\centering\bfseries\uline{\hfill\@title\hfill}}}\\
    \vspace*{56pt}
    %\renewcommand{\arraystretch}{1}
    \hspace{20pt}\begin{tabular}{cc}
      \begin{minipage}[t][29pt]{31mm}{\sihao\song\bfseries{\lan@nameapply\lan@colon}}\end{minipage}&
      \underline{\makebox[50mm]{\sihao\fsong\@author}}
      {\sihao\song\bfseries\lan@studentid\lan@colon}\underline{\makebox[32mm]{\sihao\fsong\@studentid}}
      \tabularnewline
      \begin{minipage}[t][29pt]{31mm}{\sihao\song\bfseries\lan@supervisor\lan@colon}\end{minipage}&
      \underline{\makebox[95mm]{\sihao\fsong\@advisorname\@advisortitle
        \ifcoadvisor\quad\@coadvisorname\@coadvisortitle\fi}}\tabularnewline
      \begin{minipage}[t][29pt]{31mm}{\sihao\song\bfseries\lan@applylevel\lan@colon}\end{minipage}&
      \underline{\makebox[95mm]{\sihao\fsong\ifacdemic\lan@acdemic\else\lan@professional\fi\lan@master}}\tabularnewline
      \begin{minipage}[t][29pt]{31mm}{\sihao\song\bfseries\lan@subjectnumder\lan@colon}\end{minipage}&
      \underline{\makebox[95mm]{\sihao\fsong\@subjectnumder}}\tabularnewline
      \begin{minipage}[t][29pt]{31mm}{\sihao\song\bfseries\lan@subjectname\lan@colon}\end{minipage}&
      \underline{\makebox[95mm]{\sihao\fsong\@subjectname}}\tabularnewline
      \begin{minipage}[t][29pt]{31mm}{\sihao\song\bfseries\lan@researchfield\lan@colon}\end{minipage}&
      \underline{\makebox[95mm]{\sihao\fsong\@researchfield}}\tabularnewline
    \end{tabular}\\
    \vspace*{52pt}
    \xiaosan\song{\bfseries\lan@paper\lan@finishdate}
    \underline{\makebox[20mm]{\substring{\@finishdate}{1}{4}}}\lan@year
    \underline{\makebox[15mm]{\substring{\@finishdate}{6}{7}}}\lan@month
    \underline{\makebox[15mm]{\substring{\@finishdate}{9}{10}}}\lan@day\\
  }
\end{center}
\clearpage
}

%研究生声明与授权书页
\newcommand{\statementgraduate}{
  \thispagestyle{empty}
  \newgeometry{left=3.25cm,right=3.4cm,top=4.2cm,bottom=3.8cm}
  \begin{center}{\sanhao\heiti{\lan@graduatestaementname}}\end{center}
  \vspace*{46pt}\begin{spacing}{1.17}\par
    \xiaosi\lan@graduatestaement \\[5pt]
    \rightline{\lan@signaturegraduate\lan@colon\hspace{3em}} \\[10pt]
    \rightline{\lan@signdate\lan@colon\hspace{7em}} \\[10pt]
    %{\rightline{\hspace{7em}\dotfill}}
    \rightline{\dhorline{30em}{2.5pt}}
    \vspace*{8pt}
    \begin{center}{\sanhao\heiti\lan@graduateauthtitle}\end{center}
    \vspace{18pt}
    \par\lan@graduateauthorization
    \vspace{6pt}
    \par\heiti{本学位论文属于:\,\,\,\,保\quad{}密\quad{}\raisebox{-3pt}{\yihao$\square$}\hspace{2em}在\,\raisebox{-3pt}{\yihao$\square$}年解密后，适应本授权书}
    \vspace{10pt}
    \par\heiti{\hspace{8em}不保密\quad{}\raisebox{-3pt}{\yihao$\square$}}
    \vspace*{40pt}\par\song{学位论文作者签名:\hfill{}导师签名:\hspace{7em}}
    \vspace*{10pt}\par\song{签名日期:\hfill{}签名日期:\hspace{7.3em}}
  \end{spacing}
  \clearpage
  \restoregeometry
}

%研究生内封面
\newcommand{\covergraduate}{
  \clearpage
  \thispagestyle{empty}
  \begin{center}
  \vspace*{100pt}{\heiti\yihao\bfseries\lan@university\lan@master\lan@degree\lan@paper} \\
  \vspace*{42pt}
  \hspace{0pt}{\centering\parbox[t]{14cm}{\setstretch{1.5}\centering\erhao\bfseries\heiti\@title}} \\
  \vspace*{48pt}
  \hspace{0pt}{\centering\parbox[t]{14cm}{\setstretch{1.5}\centering\sihao\bfseries\@titleeng}} \\
  \end{center}
  \par\vspace*{32pt}
  \begin{tabular}{cl}
    \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@school\lan@colon}\end{minipage} &
      {\sihao\song\bfseries\@school}\tabularnewline
    \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@aplydegree\lan@colon}\end{minipage} &
      {\sihao\song\bfseries\@aplydegree\lan@degree}\tabularnewline
    \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@majorfull\lan@colon}\end{minipage} &
      {\sihao\song\bfseries\@major}\tabularnewline
    \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@namefull\lan@colon}\end{minipage} &
      {\sihao\song\bfseries\@author}\hspace{6em}{\sihao\heiti\lan@studentid\lan@colon\quad\bfseries\@studentid}\tabularnewline
    \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@supervisor\lan@colon}\end{minipage} &
      {\sihao\song\bfseries\@advisorname\@advisortitle}\tabularnewline
    \ifcoadvisor
      \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@cosupervisor\lan@colon}\end{minipage} &
        {\sihao\song\bfseries\@coadvisorname\@coadvisortitle}\tabularnewline
    \fi
    \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@paper\lan@finishdate\lan@colon}\end{minipage} &
      {\sihao\song\bfseries\@finishdate}\tabularnewline
    \begin{minipage}[t][27pt]{31mm}{\sihao\heiti\lan@fundation\lan@colon}\end{minipage} &
      \begin{minipage}[t][27pt][l]{100mm}{\sihao\song\bfseries\@foundation}\end{minipage}
    \tabularnewline
  \end{tabular}
  \clearpage
}

%生成封面页
\ifmasterdegree
  \def\@subject {\lan@university\lan@graduatestudent\lan@graduation\lan@paper}
\else
  \def\@subject {\lan@university\lan@bachelor\lan@graduation\lan@paper}
\fi
\renewcommand{\maketitle}{%
  \begin{titlepage}
    \hypersetup{%
      pdfinfo={%
      Subject={\@subject},
      Author={\@author},
      Title={\@title}
      }
    }
  \ifbachelordegree\titlebachelor\else\titlegraduate\fi
  \restoregeometry
  \ifbachelordegree\statementbachelor\else\statementgraduate\fi
  %生成内封面
  \ifbachelordegree\coverbachelor\else\covergraduate\fi
  \end{titlepage}
}

% --- 定义新的中英文摘要环境
\newenvironment{cnabstract}[1]{
%  \newgeometry{left=3.2cm,right=3.2cm,top=3.8cm,bottom=3.8cm}
%  \setlength{\headsep}{0.2cm}
 % \setlength{\footskip}{1cm}
  \pagenumbering{Roman} %开始罗马数字
  \def\@cnkeywords {#1}
  \phantomsection
  \addcontentsline{toc}{chapter}{\lan@abstracttoc}
  \ifmasterdegree
    \chapter*{\@title}
    \vspace*{-10pt}
    \begin{center}{\xiaosi\lan@graduatestudent\lan@colonch\@author\quad\lan@subjectmajor\lan@colonch\@major\\
       \lan@advisor\lan@colonch\@advisorname\@advisortitle}\end{center}
    \vspace*{10pt}
    \begin{center}{\xiaosan\bfseries\heiti\Zhspace{25pt}{\lan@abstractcn}}\end{center}
  \else
    \chapter*{\Zhspace{25pt}{\lan@abstractcn}}
  \fi
  \begin{spacing}{1.25}\xiaosi
}{
  \end{spacing}
  \vspace{1em}
  \par{\heiti\xiaosi\lan@keywordcn\lan@colon\,}{\xiaosi\@cnkeywords}
  \clearpage
}

%英文摘要环境
\newenvironment{enabstract}[1]{
  %\newgeometry{left=3.2cm,right=3.2cm,top=3.8cm,bottom=3.8cm}
  %\setlength{\headsep}{0.2cm}
  %\setlength{\footskip}{1cm}
  \def\enkeyword {#1}
  \phantomsection
  \addcontentsline{toc}{chapter}{\lan@abstracten}
  \ifmasterdegree
    \vspace*{-5pt}
    \begin{center}{\xiaoer\bfseries\@titleeng}\end{center}
    \vspace*{10pt}
    \begin{spacing}{1.0}\centering\wuhao{
       POSTGRADUATE:\@authoreng\\
       SPECIALIZATION:\\
       Directed by \@advisortitleeng\@advisornameeng
       }\end{spacing}
    \begin{center}{\xiaosan\bfseries\lan@abstracten}\end{center}
  \else
    \chapter*{\bfseries\lan@abstracten}
  \fi
  \begin{spacing}{1.26}\sihao
}{
  \end{spacing}
  \vspace{1em}
  \par{\sihao\bfseries\lan@keyworden\lan@colon\,}{\sihao\enkeyword}
  \clearpage
  \pagenumbering{arabic}
  %\restoregeometry
}

%设置目录
\RequirePackage[titles]{tocloft}
\setcounter{tocdepth}{1} %只显示一级目录
\renewcommand{\cftbeforesecskip}{0pt} %设置节间距
\renewcommand{\cftsecfont}{\xiaosi} %设置节字体,章间距和字体在cfg文件titlecontentschapter中设置
%设置目录
\ifbachelordegree %本科格式，黑体四号
  \titlecontents{chapter}[0pt]{\heiti\sihao}{第\zhnumber{\thecontentslabel}章\quad}{}{\titlerule*[0.5pc]{.}\xiaosi\contentspage}
  \titlecontents{section}[4.5em]{\song\sihao}{\thecontentslabel\quad}{}{\titlerule*[0.5pc]{.}\xiaosi\contentspage}
\else %研究生格式，宋体小四号
  \titlecontents{chapter}[0pt]{\song\xiaosi}{第\zhnumber{\thecontentslabel}章\quad}{}{\titlerule*[0.5pc]{.}\xiaosi\contentspage}
  \titlecontents{section}[4em]{\song\xiaosi}{\thecontentslabel\quad}{}{\titlerule*[0.5pc]{.}\xiaosi\contentspage}
\fi

\renewcommand{\tableofcontents}[1][pagenum=false,toc in toc=false]{
      \chapter*{\contentsname
          \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}
      }%
      \vspace{10pt}
      \ifbachelordegree\begin{spacing}{1.2}\else\begin{spacing}{1.1}\fi
      \@starttoc{toc}\end{spacing}
      \addtocontents{toc}{\protect\thispagestyle{empty}}
      \pagenumbering{gobble}
      \clearpage{}
      \ifbachelordegree\pagenumbering{arabic}\fi
  }
% 章节格式
\RequirePackage[indentafter]{titlesec}
\RequirePackage{enumitem}
\RequirePackage{caption}
\RequirePackage{indentfirst}%首行缩进
\titleformat{\chapter}{\centering\heiti\xiaosan}{\chaptertitlename}{1em}{}%小三号黑体居中
\titlespacing*{\chapter}{0pt}{0pt}{20pt}%
\titleformat{\section}{\sihao\heiti\setstretch{1.4}}{\thesection}{5pt}{}%四号黑体
\titlespacing*{\section}{0pt}{10pt}{10pt}%
\titleformat{\subsection}{\xiaosi\setstretch{1.4}}{\thesubsection}{5pt}{}%小四号
\titlespacing*{\subsection}{0pt}{0pt}{0pt}%
\setlist{nosep}

%引用格式
\RequirePackage[pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false]{hyperref}
\RequirePackage[super,square,comma,sort&compress]{natbib}
\renewcommand{\bibsection}{\chapterstar{\lan@reference}}
\setlength{\bibsep}{0pt plus 0.3ex}

\let\oldthebibliography\thebibliography
\let\endoldthebibliography\endthebibliography
\renewenvironment{thebibliography}[1]{
  \begin{oldthebibliography}{#1}
    \setlength{\itemsep}{0em}
    \setlength{\parskip}{0em}
    \singlespacing\wuhao
}
{
  \end{oldthebibliography}
}

%%% 设置附录
\RequirePackage{appendix}
\renewcommand{\appendixname}{附录}
\let\oldappendix\appendix
\renewcommand\appendix{
  \oldappendix
  \titleformat{\chapter}{\centering\heiti\sanhao}{\chaptertitlename \thechapter}{1em}{}
  \titlecontentsappendix %
}

%%%% 设置公式格式
\AtBeginDocument{
\setlength{\abovedisplayskip}{5pt}
\setlength{\belowdisplayskip}{5pt}
\setlength{\abovedisplayshortskip}{5pt}
\setlength{\belowdisplayshortskip}{5pt}  %公式间距

}
% 设置代码环境
\usepackage{listings}
\usepackage{xcolor}
\definecolor{hellgelb}{rgb}{1,1,0.85}
\definecolor{colKeys}{rgb}{0,0,1}
\definecolor{colIdentifier}{rgb}{0,0,0}
\definecolor{colComments}{rgb}{1,0,0}
\definecolor{colString}{rgb}{0,0.5,0}
\lstset{%
     language=Matlab,%
     float=hbp,%
     basicstyle=\small\ttfamily,%
     lineskip={0.5pt},
     identifierstyle=\color{colIdentifier},%
     keywordstyle=\bfseries\color{colKeys},%
     stringstyle=\color{colString},%
     commentstyle=\small\itshape\color{colComments},%
     fontadjust=true,
     columns=fixed,
     tabsize=4,%
     frame=l,%
     framesep=3pt,
     rulesep=2pt,
     framerule=1pt,
     rulecolor=\color{cyan},
     extendedchars=true,%
     showspaces=false,%
     showstringspaces=false,%
     numbers=left,%
     numberstyle=\tiny\ttfamily,%
     numbersep=1em,%
     breaklines=true,%
     breakindent=10pt,%
     backgroundcolor=\color{gray!5},%
     breakautoindent=true,%
     captionpos=t,%
     xleftmargin=1em,%
     xrightmargin=\fboxsep%
}

\ifmasterdegree
  \renewcommand{\baselinestretch}{1.4} %研究生论文行距20pt
\else
  \renewcommand{\baselinestretch}{1.6} %本科论文行距
\fi
\setlist[enumerate]{topsep=0pt,itemsep=0pt,partopsep=0pt,parsep=0pt}
\setlength{\parindent}{2em}
\AtEndOfClass{\input{ntuthesis.cfg}}
\AtEndDocument{}
